<template>
  <view class="tab-bar-component">
    <view class="tab-box">
      <view
        class="tab-item"
        v-for="(item, index) in tabBarList"
        :key="index"
        @click="toPage(item)"
      >
        <view class="tab-image">
          <image
            :src="item.imageUrl"
            v-if="activeComponentName !== item.componentName"
            mode="widthFix"
          />
          <image
            class="active"
            :src="item.imageUrlActive"
            v-else
            mode="widthFix"
          />
        </view>
        <text
          class="title"
          :class="activeComponentName == item.componentName ? 'active' : ''"
          >{{ item.title }}</text
        >
      </view>
    </view>
  </view>
</template>

<script>
import { defineComponent, reactive, toRefs } from "vue";
export default defineComponent({
  name: "",
  props: {
    tabBarList: {
      type: Array,
      default: () => {
        return [];
      },
    },
    initComponentName: {
      type: String,
      default: "",
    },
  },
  components: {},
  setup(props, ctx) {
    const data = reactive({
      activeComponentName: props.initComponentName,
    });
    const toPage = (item) => {
      data.activeComponentName = item.componentName;
      ctx.emit("changeComponent", item.componentName);
    };
    return {
      toPage,
      ...toRefs(data),
    };
  },
});
</script>

<style scoped lang="less">
@keyframes donghua {
  0% {
    // 角度
    transform: scaleX(-1);
  }

  100% {
    transform: scaleX(1);
  }
}
.tab-bar-component {
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 99;
  display: flex;
  width: 100%;
  justify-content: space-between;
  height: 100rpx;
  background: #fff;
  box-shadow: 0 0 1rpx 1rpx rgba(0, 0, 0, 0.1);
  .tab-box {
    flex: 1;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    .tab-item {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      position: relative;
      .tab-image {
        width: 56rpx;
        image {
          width: 100%;
          display: block;
        }
        .active {
          animation: donghua 1s 1;
        }
      }
      .title {
        font-size: 20rpx;
        font-weight: 300;
        &.active {
          color: #ff0777;
        }
      }
    }
  }
}
</style>
